package com.baidu.annotation;


import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class AppTestAnnotation {
    public static void main(String[] args) {
        UserServiceImpl userService = new UserServiceImpl();

        //1.获取对象所有的方法 测试
        Class userServiceClass = UserServiceImpl.class;

        //2.利用class类获取所有方法
        Method[] declaredMethods = userServiceClass.getDeclaredMethods();

        //3.遍历
        for (Method declaredMethod : declaredMethods) {
            //3.1.判断方法的注解
            MyTest annotation = declaredMethod.getAnnotation(MyTest.class);

            //3.2.如果获取到该注解 则执行方法
            if(null != annotation){
                try {
                    declaredMethod.invoke(userService);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
